<?php

/**
 * Class Involved_ShopBusinessModel
 */

class Involved_ShopBusinessModel extends BaseModel{

    protected $table = 'shop_business';


    /**
     * 商家列表
     * @return mixed
     */
    public function YptBusinessList()
    {
        return  DB::table($this->table)
            ->where('shop_business.is_show',1)
            ->orderby('shop_business.created','desc')
            ->paginate(12);

    }

    public function YptShopBusinessList($arr)
    {
        return  DB::table($this->table)
            ->where('shop_business.is_show',1)
            ->whereIn('business_id',$arr)
            ->orderby('shop_business.created','desc')
            ->paginate(12);
    }

    /**
     * 商家详情商品列表
     * @param $business_id
     * @return mixed
     */
    public function YptBusinessShopList($business_id,$c_id)
    {
        $db1 =   DB::table($this->table);
        $db2 =   DB::table($this->table);

        $data1 = $db1
            ->where('shop_business.business_id',$business_id)
            ->first();

        if(empty($c_id)){
            $data2 = $db2
                ->select('product_name','business_name','shop_product.price','img1','product_id','shop_business.business_id')
                ->join('shop_product','shop_product.business_id','=','shop_business.business_id')
                ->where('shop_product.is_show',1)
                ->where('shop_product.business_id',$business_id)
                ->orderby('shop_product.created','desc')
                ->paginate(12);
        }else{
            $data2 = $db2
                ->select('product_name','business_name','shop_product.price','img1')
                ->join('shop_product','shop_product.business_id','=','shop_business.business_id')
                ->where('shop_product.is_show',1)
                ->where('shop_product.business_id',$business_id)
                ->where('shop_product.sort',$c_id)
                ->orderby('shop_product.created','desc')
                ->paginate(12);
        }

        return $arr = [
          'data1' => $data1,
          'data2' => $data2,
          'business_id' => $business_id,
        ];

    }





}